package com.example.music.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.music.entity.SongList;
import com.example.music.service.SongListService;
import com.example.music.utils.AjaxJson;
import com.example.music.utils.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("songList")
public class SongListController {
    @Autowired
    SongListService songListService;

    @PostMapping("add")
    public AjaxJson add(@RequestBody SongList songList) {
        Integer add = songListService.add(songList);
        System.out.println(add);
        return AjaxJson.getSuccess();
    }
    @PostMapping("update")
    public AjaxJson updateSongList(@RequestBody SongList songList){
        boolean b = songListService.updateSongList(songList);
        System.out.println(b);
        return AjaxJson.getSuccess();
    }
    @PostMapping("delete")
    public AjaxJson deleteSongList(@RequestParam int id){
        Integer integer = songListService.deleteById(String.valueOf(id));
        System.out.println(integer);
        return AjaxJson.getSuccess(integer.toString());
    }
    @PostMapping("selectById")
    public AjaxJson deleteSongList(@RequestParam Integer id){
        SongList songList = songListService.selectItemById(id.toString());
        return AjaxJson.getSuccessData(songList);
    }
    @PostMapping("selectAll")
    public AjaxJson selectAllSongList(){
        List<SongList> songLists = songListService.selectAll();
        return AjaxJson.getSuccessData(songLists);
    }
    @PostMapping("songListOfTitle")
    public AjaxJson songListOfTitle(@RequestParam String title){
        List<SongList> songLists = songListService.songListOfTitle(title);
        return AjaxJson.getSuccessData(songLists);
    }
    @PostMapping("songListOfStyle")
    public AjaxJson songListOfStyle(@RequestParam String style){
        List<SongList> songLists = songListService.songListOfStyle(style);
        return AjaxJson.getSuccessData(songLists);
    }
    @PostMapping("updateSongPic")
    public AjaxJson updateSongPic(@RequestParam Integer id, @RequestParam("file") MultipartFile pic) {
        return songListService.updateSongListPic(id,pic);
    }
    @PostMapping("songStyle")
    public AjaxJson songStyle() {
        return songListService.songStyle();
    }
}
